import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getLoginApi } from '@/apis/user'

export const useUserStore = defineStore(
  'weather-user',
  () => {
    // 用户信息
    const userInfo = ref({})
    // 登录获取用户信息
    const getUserInfo = async data => {
      const res = await getLoginApi(data)
      userInfo.value = res.data.data
    }
    // 删除用户信息
    const removeUser = () => {
      userInfo.value = {}
    }
    return {
      userInfo,
      getUserInfo,
      removeUser
    }
  },
  {
    persist: true
  }
)
